<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 300px;
            height: 300px;
            /* 水平垂直居中 */
            background: yellow;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -150px;
        }
        .box2{
            width: 300px;
            height: 300px;
            background: blue;
            position: relative;
        }
        .box3{
            width: 100px;
            height: 100px;
            background-color: red;
            /* 子盒子水平垂直居中 */
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
        }
        .box4{
            width: 300px;
            height: 300px;
            background: lightblue;
            position: relative;
        }
        .box5{
            width: 100px;
            height: 100px;
            background-color: red;
            /* 子盒子水平垂直居中 */
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        }
        .box6{
            width: 300px;
            height: 300px;
            background: gray;
            position: relative;
        }
        .box7{
            width: 100px;
            height: 100px;
            background-color: red;
            /* 子盒子水平垂直居中 */
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        }
        .box8{
            width: 300px;
            height: 300px;
            background: green;
            /* 父盒子设置 */
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .box9{
            width: 100px;
            height: 100px;
            background-color: red;   
        }
        .box10{
            width: 300px;
            height: 300px;
            background: pink;
            display: table-cell; 
            text-align: center; 
            vertical-align: middle;
        }
        .box11{
            width: 100px;
            height: 100px;
            background-color: red;
            /* 子盒子水平垂直居中 */
            display: inline-block;
        }
    </style>
</head>
<body>
    <div class="box">单一</div>
    <div class="box2">
        <div class="box3">子元素1</div>
    </div>
    <div class="box4">
        <div class="box5">子元素2</div>
    </div>
    <div class="box6">
        <div class="box7">子元素3</div>
    </div>
    <div class="box8">
        <div class="box9">子元素4</div>
    </div>
    <div class="box10">
        <div class="box11">子元素5</div>
    </div>
</body>
</html>